package malus.shaofeng.com.beiwomusic.model;

import com.lidroid.xutils.db.annotation.Column;
import com.lidroid.xutils.db.annotation.Finder;
import com.lidroid.xutils.db.annotation.Foreign;
import com.lidroid.xutils.db.annotation.Id;
import com.lidroid.xutils.db.annotation.NoAutoIncrement;
import com.lidroid.xutils.db.annotation.Table;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by aaa on 15-3-10.
 */
@Table(name = "newStoryMusic")
public class NewStoryMusic implements Serializable{
            @Id(column = "music_id")
            @NoAutoIncrement
            private long music_id;// 4754,
            @Column(column = "music_name")
            private String music_name;// "当爱已成往事",
            @Column(column = "duration")
            private long duration;// 279,
            @Column(column = "high_url")
            private String high_url;// "http://cdn.kxai.cn/res/qms/20140423/mp3/52/7c/527cba5cfd704061a799ea1a947d6159_64.mp3",
            @Column(column = "low_url")
            private String low_url;// "http://cdn.kxai.cn/res/qms/20140423/mp3/52/7c/527cba5cfd704061a799ea1a947d6159_32.mp3",

            @Foreign(column = "music_lyricId",foreign = "music_id")
            private NewStoryMusicLyric music_lyric;//
            @Finder(valueColumn = "music_id",targetColumn = "newStoryMusicId")
            private List<Artist> artists;
            @Foreign(column = "albumId",foreign = "album_id")
            private Album album;

    public void parseJSON(JSONObject json){
        if (json!=null){
             music_id=json.optLong("music_id");
             music_name=json.optString("music_name");
             duration=json.optLong("duration");
            high_url=json.optJSONObject("music_file").optString("high_url");
            low_url=json.optJSONObject("music_file").optString("low_url");

            JSONObject object=json.optJSONObject("lyric");
            music_lyric=new NewStoryMusicLyric();
            music_lyric.parseJSON(object);

            JSONArray jsonArray = json.optJSONArray("artists");
            artists=new LinkedList<Artist>();
            for (int i=0;i<jsonArray.length();i++){
                try {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    Artist artist=new Artist();
                    artist.parseJSON(jsonObject);
                    artists.add(artist);

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            object=json.optJSONObject("album");
            album=new Album();
            album.parseJSON(object);

        }
    }

    public long getMusic_id() {
        return music_id;
    }

    public void setMusic_id(long music_id) {
        this.music_id = music_id;
    }

    public String getMusic_name() {
        return music_name;
    }

    public void setMusic_name(String music_name) {
        this.music_name = music_name;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public String getHigh_url() {
        return high_url;
    }

    public void setHigh_url(String high_url) {
        this.high_url = high_url;
    }

    public String getLow_url() {
        return low_url;
    }

    public void setLow_url(String low_url) {
        this.low_url = low_url;
    }

    public NewStoryMusicLyric getMusic_lyric() {
        return music_lyric;
    }

    public void setMusic_lyric(NewStoryMusicLyric music_lyric) {
        this.music_lyric = music_lyric;
    }

    public List<Artist> getArtists() {
        return artists;
    }

    public void setArtists(List<Artist> artists) {
        this.artists = artists;
    }

    public Album getAlbum() {
        return album;
    }

    public void setAlbum(Album album) {
        this.album = album;
    }
}
